home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1995 October / EnigmA AMIGA RUN 01 (1995)(G.R. Edizioni)(IT)[!][issue 1995-10][Aminet 7].iso / Aminet / mus / play / tracker_4_31.lzh / tracker / extern.h < prev    next >
Text File  |  1995-05-15  |  18KB  |  578 lines

  1. /* extern.h 
  2.     vi:ts=3 sw=3:
  3.  */
  4.  
  5. /* $Id: extern.h,v 4.19 1995/05/15 12:19:53 espie Exp espie $
  6.  * $Log: extern.h,v $
  7.  * Revision 4.19  1995/05/15  12:19:53  espie
  8.  * *** empty log message ***
  9.  *
  10.  * Revision 4.18  1995/05/12  13:53:18  espie
  11.  * New synchronization primitive.
  12.  *
  13.  * Revision 4.17  1995/03/03  14:23:59  espie
  14.  * Color independence.
  15.  *
  16.  * Revision 4.16  1995/03/01  15:24:51  espie
  17.  * Proto for set_data_width.
  18.  *
  19.  * Revision 4.15  1995/02/23  22:40:44  espie
  20.  * Changed call to output_samples, added # of bits.
  21.  *
  22.  * Revision 4.14  1995/02/21  21:13:16  espie
  23.  * Cleaned up source. Moved minor pieces of code around.
  24.  *
  25.  * Revision 4.13  1995/02/21  17:54:32  espie
  26.  * Internal problem: buggy RCS. Fixed logs.
  27.  *
  28.  * Revision 4.10  1995/02/20  16:49:58  espie
  29.  * Added nearest_note.
  30.  *
  31.  * Revision 4.9  1995/02/14  04:02:28  espie
  32.  * Changed amiga prototype.
  33.  *
  34.  * Revision 4.8  1995/02/06  14:50:47  espie
  35.  * Changed sample_info.
  36.  *
  37.  * Revision 4.7  1995/02/01  20:41:45  espie
  38.  * Added color.
  39.  *
  40.  * Revision 4.6  1995/02/01  16:39:04  espie
  41.  * Added LEFT_SIDE/RIGHT_SIDE defines (finally !)
  42.  *
  43.  * Revision 4.1  1994/02/04  14:54:08  espie
  44.  * Fixed up ansi C stupid bug.
  45.  * Lots of new proto for all functions.
  46.  * Generalized open.c.
  47.  * Comments.
  48.  * Added checkbrk.
  49.  * General cleanup.
  50.  * Suppressed some unused code.
  51.  * Better portability.
  52.  * Removed init_display.
  53.  * No more reentrency problems with INIT_ONCE.
  54.  * Protos for ui: notice, info, scroller, pattern display.
  55.  * Mostly working.
  56.  * Just dies with a guru.
  57.  * Plus timing problems at start.
  58.  * New prototypes.
  59.  * Initial revision
  60.  *
  61.  * Revision 3.15  1993/12/04  16:12:50  espie
  62.  * Amiga support.
  63.  * Added bg/fg test.
  64.  * stty_sane.
  65.  * New audio functions.
  66.  * Simplified delay_pattern.
  67.  * Protracker commands.
  68.  * New release.
  69.  *
  70.  * Revision 2.19  1992/11/17  17:06:25  espie
  71.  * Lots of new functions to account for new interface.
  72.  * open_file support.
  73.  * Separated mix/stereo stuff.
  74.  * Added possibility to get back to MONO for the sgi.
  75.  * Added stereo capabilities to the indigo version.
  76.  * Added some new song types to automatize the choice process.
  77.  * Moved resampling to audio, added prototype.
  78.  * Added SAMPLE_FAULT, for trying to play
  79.  * a note without a sample (not really an error).
  80.  *
  81.  * Revision 1.7  1991/11/08  14:25:55  espie
  82.  * Modified audio prototype so that you can change
  83.  * frequency.
  84.  * Added prototype for release_song.
  85.  * Added arpeggio effect.
  86.  * Added entries for new effects.
  87.  * Added entries for commands.c.
  88.  */
  89.  
  90.  
  91. /*--------------------------- resample.c -------------------------*/
  92. #define ACCURACY 12
  93. #define fix_to_int(x) ((x) >> ACCURACY)
  94. #define int_to_fix(x) ((x) << ACCURACY)
  95. #define fractional_part(x) ((x) & (total_step - 1))
  96. #define total_step     (1 << ACCURACY)
  97.  
  98. /* release_audio_channels:
  99.  * free every audio channel previously allocated
  100.  */
  101. XT void release_audio_channels P((void));
  102.  
  103. #define LEFT_SIDE 0
  104. #define RIGHT_SIDE 1
  105. #define BASE_AUDIO 20
  106. #define AUDIO_SIDE (BASE_AUDIO)
  107.  
  108. /* chan = new_channel_tag_list(prop):
  109.  * allocates a new channel for the current song
  110.  * properties: AUDIO_SIDE LEFT_SIDE (default)/RIGHT_SIDE
  111.  */
  112. XT struct audio_channel *new_channel_tag_list P((struct tag *prop));
  113.  
  114. /* init_tables(oversample, frequency):
  115.  * precomputes the step_table and the pitch_table
  116.  * according to the desired oversample and frequency.
  117.  * This is static, you can call it again whenever you want.
  118.  * Adjust the currently used audio channels if needed.
  119.  */
  120. XT void init_tables P((int oversample, int frequency));
  121.  
  122. /* set_data_width(side_width, sample_width):
  123.  * accumulated data on each side will have width side_width bits,
  124.  * and each sample will never be greater than sample_width
  125.  */
  126. XT void set_data_width P((int side, int sample));
  127.  
  128. /* resample(oversample, number):
  129.  * send number samples out computed according
  130.  * to the current state of channels
  131.  * and oversample.
  132.  */
  133. XT void resample P((int oversample, int number));
  134.  
  135. /* play_note(au, samp, pitch)
  136.  * set audio channel au to play samp at pitch
  137.  */
  138. XT void play_note P((struct audio_channel *au, struct sample_info *samp, \
  139. int pitch));
  140.  
  141. /* set_play_pitch(au, pitch):
  142.  * set channel au to play at pitch pitch
  143.  */
  144. XT void set_play_pitch P((struct audio_channel *au, int pitch));
  145.  
  146. /* set_play_volume(au, volume):
  147.  * set channel au to play at volume volume
  148.  */
  149. XT void set_play_volume P((struct audio_channel *au, int volume));
  150.  
  151. /* set_play_position(au, pos):
  152.  * set position in sample for channel au at given offset
  153.  */
  154. XT void set_play_position P((struct audio_channel *au, int pos));
  155.  
  156.  
  157. /*--------------------------- empty.c ----------------------------*/
  158. /* empty = empty_sample():
  159.  * return a suitable empty sample
  160.  */
  161. XT struct sample_info *empty_sample P((void));
  162.  
  163.  
  164. /*--------------------------- automaton.c ------------------------*/
  165. /* init_automaton(a, song, start):
  166.  * put the automaton a in the right state to play song from pattern #start.
  167.  */
  168. XT void init_automaton P((struct automaton *a, struct song *song, int start));
  169.  
  170. /* next_tick(a):
  171.  * set up everything for the next tick.
  172.  */
  173. XT void next_tick P((struct automaton *a));
  174.  
  175.  
  176. /*--------------------------- commands.c -------------------------*/
  177. /* init_effects(): set up all data for the effects
  178.  * can't be set up as an autoinit
  179.  */
  180. XT void init_effects P((void (*table[])()));
  181.  
  182. /* do_nothing: this is the default behavior for an effect.
  183.  */
  184. XT void do_nothing P((struct channel *ch));
  185.  
  186.  
  187. /*--------------------------- dump_song.c ------------------------*/
  188. /* dump_song(s): 
  189.  * display some information pertinent to the given song s
  190.  */
  191. XT void dump_song P((struct song *song));
  192.  
  193.  
  194. /*--------------------------- display.c --------------------------*/
  195. /* dump_event(ch, e): dump event e as occuring on channel ch
  196.  * (some events need the current channel state for a correct dump)
  197.  * special case: ch == 0 means current set of events done
  198.  */
  199. XT void dump_event P((struct channel *ch, struct event *e));
  200.  
  201. /* dump_delimiter(): add a delimiter to the current dump, to 
  202.  * separate left channels from right channels, for instance
  203.  */
  204. XT void dump_delimiter P((void));
  205.  
  206.  
  207. /*--------------------------- main.c -----------------------------*/
  208. #define OLD 0
  209. #define NEW 1
  210. /* special new type: for when we try to read it as both types.
  211.  */
  212. #define BOTH 2
  213. /* special type: does not check the signature */
  214. #define NEW_NO_CHECK 3
  215.  
  216.  
  217. /* error types. Everything is centralized,
  218.  * and we check in some places (see st_read, player and main)
  219.  * that there was no error. Additionnally signal traps work
  220.  * that way too.
  221.  */
  222.  
  223. /* normal state */
  224. #define NONE 0  
  225. /* read error */
  226. #define FILE_TOO_SHORT 1
  227. #define CORRUPT_FILE 2
  228. /* trap error: goto next song right now */
  229. #define NEXT_SONG 3
  230. /* run time problem */
  231. #define FAULT 4
  232. /* the song has ended */
  233. #define ENDED 5
  234. /* unrecoverable problem: typically, trying to 
  235.  * jump to nowhere land.
  236.  */
  237. #define UNRECOVERABLE 6
  238. /* Missing sample. Very common error, not too serious. */
  239. #define SAMPLE_FAULT 7
  240. /* New */
  241. #define PREVIOUS_SONG 8
  242. #define OUT_OF_MEM 9
  243. XT int error;
  244.  
  245.  
  246. /*--------------------------- notes.c ----------------------------*/
  247. #define NUMBER_NOTES 120
  248. #define NUMBER_FINETUNES 17
  249. /* set of pitch for all notes for all finetunes (used heavily by protracker)
  250.  */
  251. XT short pitch_table[NUMBER_NOTES][NUMBER_FINETUNES];    /* 120 * 17 = big ! */
  252.  
  253. /* note = find_note(pitch):
  254.  * find note corresponding to a given pitch
  255.  */
  256. XT int find_note P((int pitch));
  257.  
  258. /* pitch = nearest_note(pitch, finetune):
  259.  * find entire note with the nearest pitch with the given finetune
  260.  */
  261. XT int nearest_note P((int pitch, int finetune));
  262.  
  263. /* oldtranspose = transpose_song(song, newtranspose):
  264.  * tranpose whole song to a new pitch
  265.  */
  266. XT int transpose_song P((struct song *song, int newtranspose));
  267.  
  268. /* name = name_of_note(note):
  269.  * name of the note. Warning! This name is only valid until a new call 
  270.  * to name_of_note (static storage)
  271.  */
  272. XT char *name_of_note P((int note));
  273.  
  274.  
  275. /*--------------------------- open.c -----------------------------*/
  276. /* handle = open_file(filename, mode, path):
  277.  * transparently open a compressed file.
  278.  */
  279. XT struct exfile *open_file P((char *fname, char *fmode, char *path));
  280.  
  281. /* close_file(handle):
  282.  * close a file that was opened with open_file.
  283.  */
  284. XT void close_file P((struct exfile *file));
  285.  
  286. /* analogous of fgetc, ftell, fread, and rewind */
  287. XT int getc_file P((struct exfile *file));
  288. XT int tell_file P((struct exfile *file));
  289. XT int read_file P((void *p, int s, int n, struct exfile *file));
  290. XT void rewind_file P((struct exfile *file));
  291.  
  292.  
  293. /*--------------------------- st_play.c --------------------------*/
  294. /* reset_note(ch, note, pitch):
  295.  * set channel ch to play note at pitch pitch
  296.  */
  297. XT void reset_note P((struct channel *ch, int note, int pitch));
  298.  
  299. /* set_current_pitch(ch, pitch):
  300.  * set ch to play at pitch pitch
  301.  */
  302. XT void set_current_pitch P((struct channel *ch, int pitch));
  303.  
  304. /* set_current_volume(ch, volume):
  305.  * set channel ch to play at volume volume
  306.  */
  307. XT void set_current_volume P((struct channel *ch, int volume));
  308.  
  309. /* set_temp_volume(ch, volume):
  310.  * set channel ch to play at volume volume, but without storing it
  311.  * (used only for tremolo)
  312.  */
  313. XT void set_temp_volume P((struct channel *ch, int volume));
  314.  
  315. /* set_position(ch, pos):
  316.  * set position in sample for current channel at given offset
  317.  */
  318. XT void set_position P((struct channel *ch, int pos));
  319.  
  320. /* init_player(oversample, frequency):
  321.  * sets up the player for a given oversample and
  322.  * output frequency.
  323.  * Note: we can call init_player again to change oversample and
  324.  * frequency.
  325.  */
  326. XT void init_player P((int o, int f));
  327.  
  328. /* play_song(song, start):
  329.  * play the song.  return tags as shown in get_ui 
  330.  */
  331. XT struct tag *play_song P((struct song *song, int start));
  332.  
  333.  
  334. /*--------------------------- st_read.c --------------------------*/
  335. /* s = read_song(f, type):
  336.  * tries to read f as a song of type NEW/OLD/NEW_NOCHECK
  337.  * returns NULL (and an error) if it doesn't work.
  338.  * Returns a dynamic song structure if successful.
  339.  */
  340. XT struct song *read_song P((struct exfile *f, int type));
  341.  
  342. /* release_song(s):
  343.  * release all the memory song occupies.
  344.  */
  345. XT void release_song P((struct song *song));
  346.  
  347.  
  348. /*--------------------------- setup_audio.c ----------------------*/
  349. /* setup_audio(ask_freq, stereo, oversample):
  350.  * setup the audio output with these values 
  351.  */
  352. XT void setup_audio P((int f, int s, int o));
  353.  
  354. /*--------------------------- audio.c ----------------------------*/
  355. /* frequency = open_audio(f, s):
  356.  * try to open audio with a sampling rate of f, and eventually stereo.
  357.  * We get the real frequency back. If we ask for 0, we
  358.  * get the ``preferred'' frequency.
  359.  * Note: we have to close_audio() before we can open_audio() again.
  360.  * Note: even if we don't ask for stereo, we still have to give a
  361.  * right and left sample.
  362.  */
  363. XT int open_audio P((int f, int s));
  364. /* close_audio():
  365.  * returns the audio to the system control, doing necessary
  366.  * cleanup
  367.  */
  368. XT void close_audio P((void));
  369. /* set_mix(percent): set mix channels level.
  370.  * 0: spatial stereo. 100: mono.
  371.  */
  372. XT void set_mix P((int percent));
  373.  
  374. /* output_samples(l, r, n): outputs a pair of stereo samples.
  375.  * Samples are n bits signed.
  376.  * Output routine should be able to face anything from 16 to 25
  377.  */
  378. XT void old_output_samples P((int left, int right));
  379. XT void output_samples P((int left, int right, int n));
  380.  
  381. /* flush_buffer(): call from time to time, because buffering
  382.  * is done by the program to get better (?) performance.
  383.  */
  384. XT void flush_buffer P((void));
  385.  
  386. /* discard_buffer(): try to get rid of the buffer contents
  387.  */
  388. XT void discard_buffer P((void));
  389.  
  390. /* new_freq = update_frequency():
  391.  * if !0, frequency changed and playing should be updated accordingly
  392.  */
  393. XT int update_frequency P((void));
  394.  
  395. /* bits = output_resolution()
  396.  * returns the number of bits expected for the output.
  397.  * Not necessary to use 16 bit samples if output is to be 8 bits
  398.  * for instance. Return 16 by default
  399.  */
  400. XT int output_resolution P((void));
  401.  
  402. /* set_synchro(boolean):
  403.  * try to synchronize audio output by using a smaller buffer
  404.  */
  405. XT void set_synchro P((int s));
  406.  
  407. /* sync_audio(function, parameter):
  408.  * call function(parameter) when audio finally gets to the current point
  409.  */
  410.  
  411. XT void sync_audio P((void (*function)(void *), void *parameter));
  412.  
  413. #ifdef SPECIAL_SAMPLE_MEMORY
  414. XT GENERIC alloc_sample P((int len));
  415. XT void free_sample P((GENERIC s));
  416. XT int obtain_sample P((GENERIC start, int l, struct exfile *f));
  417.  
  418. #else
  419. #define alloc_sample(len)        calloc(len, 1)
  420. #define free_sample(sample)        free(sample)
  421. #define obtain_sample(start, l, f)    read_file(start, 1, l, f)
  422. #endif
  423.  
  424.  
  425. /*--------------------------- tools.c ----------------------------*/
  426. /* v = read_env(name, default):
  427.  * read a scalar value in the environment
  428.  */
  429. XT int read_env P((char *name, int def));
  430.  
  431.  
  432. /*--------------------------- autoinit.c -------------------------*/
  433. /* used for decentralizing initialization/termination of various
  434.  * system routines
  435.  */
  436.  
  437. /* end_all(s): the program must exit now, after displaying s to the user, 
  438.  * usually through notice and calling all stacked at_end() functions. 
  439.  * s may be 0 for normal exit. DO NOT use exit() anywhere in tracker 
  440.  * but end_all() instead.
  441.  */
  442. XT void end_all P((char *s));
  443.  
  444. /* at_end(cleanup): stack cleanup to be called at program's termination
  445.  */
  446. XT void at_end P((void (*cleanup)(void)));
  447.  
  448. /* INIT_ONCE: macro for autoinitialization of routines.
  449.  * modules that need an init routine should LOCAL void INIT = init_routine,
  450.  * and add INIT_ONCE; at EVERY possible first entry point for their routine.
  451.  * (I mean every, don't try to second-guess me !)
  452.  */
  453. #define INIT_ONCE    if (INIT){void (*func)P((void)) = INIT; INIT = 0; (*func)();}
  454.  
  455.  
  456. /*--------------------------- $(UI)/ui.c ------------------------*/
  457. /* see unix/ui.c for the general unix implementation.
  458.  * The old may_getchar() has been replaced by the tag-based
  459.  * get_ui
  460.  */
  461. /* get_ui(): returns an array of tags that reflect the current user-interface
  462.  * actions. Unknown tags WILL be ignored.
  463.  * Note that get_ui will be called about once every tick, providing a poor man's
  464.  * timer to the interface writer if needed to code multiple actions on the same
  465.  * user-input. See unix/termio.c for a good example.
  466.  * see amiga/ui.c for the correct way to do it when you have a real timer.
  467.  *
  468.  * VERY IMPORTANT: who do the tags belong to ?
  469.  *   as a general rule, result (and their values) MUST only be considered
  470.  *   valid between two calls to get_ui ! Be careful to call get_ui ONLY at
  471.  *   reasonable places.
  472.  *   One exception: structures that are dynamically allocated (like UI_LOAD_SONG
  473.  *   values) will ONLY get freed when you ask for it !
  474.  */
  475. XT struct tag *get_ui P((void));
  476. #define BASE_UI 10
  477. #define UI_NEXT_SONG    (BASE_UI)            /* load next song */
  478. #define UI_PREVIOUS_SONG (BASE_UI + 1)    /* load previous song */
  479. #define UI_LOAD_SONG (BASE_UI + 2)        /* load song. Name as value */
  480. #define UI_SET_BPM (BASE_UI + 3)          /* set beat per minute to value */
  481. #define UI_JUMP_TO_PATTERN (BASE_UI + 4)  /* jump to pattern #value.  Use 
  482.                                                         * display_pattern to keep in 
  483.                                                          * sync with the player */
  484. #define UI_RESTART (BASE_UI + 5)          /* restart current song. Not 
  485.                                                          * quite jump to 0 */
  486. #define UI_QUIT (BASE_UI + 6)             /* need I say more ? */
  487. #define UI_DISPLAY (BASE_UI + 7)          /* status of scrolling window: 
  488.                                                          * true or false */
  489.  
  490.  
  491. /* st_play.c translates the get_ui() tags in a standard way.
  492.  * Actually it doesn't translate anything right now...
  493.  */
  494. #define BASE_PLAY 20
  495. #define PLAY_NEXT_SONG UI_NEXT_SONG
  496. #define PLAY_PREVIOUS_SONG UI_PREVIOUS_SONG
  497. #define PLAY_LOAD_SONG UI_LOAD_SONG
  498.  
  499. #define PLAY_ERROR BASE_PLAY
  500. #define PLAY_ENDED (BASE_PLAY+1)
  501.  
  502. /* Most of these functions are information display function.
  503.  * A correct implementation should heed run_in_fg() if needed
  504.  */
  505.  
  506. /* notice(s): important message for the user (terminal error maybe).
  507.  * take extra pain to make it apparent even if run in background
  508.  */
  509. XT void notice P((char *s));
  510.  
  511. /* status(s): some indication of the system current status... 
  512.  * Used for fleeing error messages too. 
  513.  * s = 0 is valid and indicates return to the default status.
  514.  */
  515. XT void status P((char *s));
  516.  
  517. /* begin_info: open a logical information window.
  518.  * returns 0 if the window couldn't be opened.
  519.  * A NULL window shouldn't be used, but don't count on it !
  520.  */
  521. XT GENERIC begin_info P((char *title));
  522. /* info(handle, line): add a line to the info window,
  523.  * completing the current line if applicable
  524.  */
  525. XT void info P((GENERIC handle, char *line));
  526. /* infos(handle, line): add to the current line of the info window
  527.  */
  528. XT void infos P((GENERIC handle, char *s));
  529. /* end_info(handle): this window is complete...
  530.  */
  531. XT void end_info P((GENERIC handle));
  532.  
  533. /* Scrolling score display:
  534.  * new_scroll() returns a writable buffer of a suitable length for n tracks
  535.  * in which display.c will write what it needs.
  536.  * It can return 0 if not applicable.
  537.  */
  538. XT char *new_scroll P((void));
  539.  
  540. /* set_number_tracks(n) sets the number of tracks for new_scroll, in order
  541.  * to allocate room accordingly
  542.  */
  543. XT void set_number_tracks P((int n));
  544.  
  545. /* scroll: returns this scrolling line to the program. Note that
  546.  * scroll doesn't take any argument, and implies calls to new_scroll/scroll
  547.  * are paired. After a call to scroll, the last pointer returned by new_scroll
  548.  * should be considered invalid !
  549.  */
  550. XT void scroll P((void));
  551.  
  552. /* display_pattern(current, total, real): we are at current/total(real) 
  553.  * in the current song
  554.  * may be used as a poor man's timer.
  555.  */
  556. XT void display_pattern P((int current, int total, int real));
  557.  
  558. /* song_title(s): the current song title is s.
  559.  * ui implementors: Don't count on this pointer remaining valid AFTER the call,
  560.  * make a copy if needed
  561.  */
  562. XT void song_title P((char *s));
  563.  
  564. /* boolean checkbrk():
  565.  * check whether a break occured and we should end right now.
  566.  * Call it often enough (like when loading songs and stuff)
  567.  */
  568. XT int checkbrk P((void));
  569.  
  570.  
  571. /*--------------------------- color.c ----------------------------*/
  572. /* s = write_color(base, color):
  573.  * write sequence to switch to color color at base, returning
  574.  * position after the sequence
  575.  */
  576. XT char *write_color P((char *base, int color));
  577.  
  578.